package com.fivefu.core.hik.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fivefu.core.hik.entity.DbHikVehicle;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

//根据车牌号码更新车辆点位信息
public class EncodeVehicleShapestr {

    @ApiModelProperty(value = "时间")
    private String time;

    @ApiModelProperty(value = "经度")
    private Long longitude;

    @ApiModelProperty(value = "纬度")
    private Long latitude;

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public Long getLongitude() {
        return longitude;
    }

    public void setLongitude(Long longitude) {
        this.longitude = longitude;
    }

    public Long getLatitude() {
        return latitude;
    }

    public void setLatitude(Long latitude) {
        this.latitude = latitude;
    }

    @Override
    public String toString() {
        return "EncodeVehicleShapestr{" +
                "time='" + time + '\'' +
                ", longitude='" + longitude + '\'' +
                ", latitude='" + latitude + '\'' +
                '}';
    }

    public DbHikVehicle addShapestrData(Long vehicleLicensePlate) throws ParseException {
        String oldDateStr = this.time;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");  //yyyy-MM-dd'T'HH:mm:ss.SSSZ
        Date date = df.parse(oldDateStr);
        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df2.format(date);
        LocalDateTime localDateTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        double minute = localDateTime.getMinute();
        double second = localDateTime.getSecond();
        double longitude = this.longitude;
        double latitude = this.latitude;
        Double actualLonformat = new BigDecimal((longitude / 3600 / 100) - (minute / 60 / 100 - second / 100)).setScale(15, RoundingMode.HALF_UP).doubleValue();
        Double actualLanformat = new BigDecimal((latitude / 3600 / 100) - (minute / 60 / 100 - second / 100)).setScale(15, RoundingMode.HALF_UP).doubleValue();
        String shapestr = "[" + actualLonformat + "," + actualLanformat + "]";
        DbHikVehicle vehicle = new DbHikVehicle();
        vehicle.setId(vehicleLicensePlate);
        vehicle.setShapestr(shapestr);
        vehicle.setUpdatedTime(LocalDateTime.now());
        //device.setIsDelete(0);//是否删除0否1是
        return vehicle;
    }

}
